﻿
/*
 *Haiwi@20150329
 *弹出iframe模式框（无标题栏）
 *调用方法：
 *（1）关闭时候无回调函数
 *      popWin.showWin("http://www.csdn.net",1000,600);
 *（2）关闭后时候执行回调函数
 *      popWin.showWin("http://www.csdn.net",1000,600,function(){alert("关闭并执行回调函数")}); 
 */
var popWin = {
    scrolling: 'auto',//是否显示滚动条 no,yes,auto
    closeCallBack:null,

    init: function() {
        this.mouseClose();
        this.closeMask();
    },

    showWin: function(src, width, height, callBackBeforeClose) {
        if(callBackBeforeClose!=undefined && callBackBeforeClose!=null){
            closeCallBack=callBackBeforeClose;
        }
    	var titleDivHeight=0;
        var iframeHeight = height - titleDivHeight;
        var marginLeft = width / 2;
        var marginTop = height / 2;
        var inntHtml = '';
        inntHtml += '<div id="mask" style="width:100%; height:100%; position:fixed; top:0; left:0; z-inde:1999;background:#cccccc; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity:0.5;"></div>'
        inntHtml += '<div id="maskTop" style="width: ' + width + 'px; height: ' + height + 'px; border: #999999 1px solid; background: #fff; color: #333; position: fixed; top: 50%; left: 50%; margin-left: -' + marginLeft + 'px; margin-top: -' + marginTop + 'px; z-index: 2999; filter: progid:DXImageTransform.Microsoft.Shadow(color=#909090,direction=120,strength=4); -moz-box-shadow: 2px 2px 10px #909090; -webkit-box-shadow: 2px 2px 10px #909090; box-shadow: 2px 2px 10px #909090;">'
        inntHtml += '<div id="maskTitle" style=" height: '+titleDivHeight+'px; line-height: 50px; font-family: Microsoft Yahei; font-size: 20px; color: #333333; padding-left: 20px; background-image: url(); border-bottom: 1px solid #999999; position: relative;">'
        inntHtml += ''
        inntHtml += '<div id="popWinClose" style="width: 28px; height: 28px; cursor: pointer; position: absolute; top: -12px; right: -9px; background-image: url();"></div>'
        inntHtml += '</div>'
        inntHtml += '<iframe width="' + width + '" height="' + iframeHeight + '" frameborder="0" scrolling="' + this.scrolling + '" src="' + src + '"></iframe>';
        inntHtml += '</div>'
        $("body").append(inntHtml);
        this.init();
    },

    mouseClose: function() {
        $("#popWinClose").on('mouseenter', 
        function() {
            $(this).css("background-image", "url()");

        });
        $("#popWinClose").on('mouseleave', 
        function() {
            $(this).css("background-image", "url()");

        });

    },

    closeMask: function() {
        $("#popWinClose").on('click', function() {
            $("#mask,#maskTop").fadeOut(function() {
                $(this).remove();
            });
            if(closeCallBack!=undefined && closeCallBack!=null){
                closeCallBack();
            }
        });
    }
};